#! /usr/bin/env python
# Author: Natan 'whatah' Zohar
# License: GPLv2 (at the moment)

# Watch out, there is a compressed glade file at the end.

import gobject
import gtk
import gtk.glade
import os
import signal
import subprocess
import sys
import threading
import time
import zlib

gtk.gdk.threads_init()

NEW         =   "NEW"
DELETE      =   "DELETE"
JOIN        =   "JOIN"
LEAVE       =   "LEAVE"
KICK        =   "KICK"
ONLINE      =   "logged in"
OFFLINE     =   "offline"
TIMEOUT     =   5
GLADE_DATA  =   None


class Output:
    def __init__(self, outfunc):
        self.output = outfunc
        
    def write(self, text):
        self.output(text)

class PersonObj(dict):
    def __getattr__(self, attr):
        return self[attr]
    
    def __setattr__(self, attr, value):
        self[attr] = value

class Executor:
    def kill_after_timeout(self, proc, timeout):
        while timeout > 0:
            time.sleep(1)
            if not proc.returncode is None:
                return
            timeout -= 1
        #TODO: use the windows kill API if we are not on *nix or mac. 
        os.kill(proc.pid, signal.SIGKILL)
        proc.timeout = True
    
    def execute(self, cmd, timeout):
        subproc = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
        subproc.timeout = False

        # start the kill timer.
        killthread = threading.Thread(target=self.kill_after_timeout, args=[subproc, timeout])
        killthread.start()

        if not subproc.returncode:
            subproc.wait()
        if subproc.timeout:
            raise IOError("Program '%s' timed out after %s seconds" % (' '.join(cmd), timeout))
        
        output = subproc.stdout.read()
        self.returncode = subproc.returncode
        self.output = output
        return output

class HamParser:
    def __init__(self):
        self.dict = {}
        self.rooms = {}
        self.online = {}
        self.names = {}
        self.lock = threading.Lock()
        self.executor = Executor()

    def __getattr__(self, attr):
        try:
            return self.dict[attr]
        except KeyError:
            return None
    
    def readStatus(self):
        try:
            for line in open(os.path.expanduser("~/.hamachi/state")).readlines():
                if line.strip() == "":
                    continue
                line = line.split()
                if len(line) == 2:
                    self.dict[line[0].strip().lower()] = line[1].strip()
        except IOError:
            print "Is hamachi properly configured?"

        lines = self.sendCommand()
        for line in lines:
            if line.strip() == "":
                continue
            line = line.split(':')
            if len(line) == 2:
                self.dict[line[0].strip()] = line[1].strip()

    def sendCommand(self, *args):
        cmd = ["hamachi"]
        cmd.extend(args)
        self.lock.acquire()
        try:
            self.lastOutput = self.executor.execute(cmd, TIMEOUT)
            self.lastLines = self.lastOutput.split('\n')
            self.returncode = self.executor.returncode
        except IOError, e:
            print e
            self.lastLines = []
        self.lock.release()
        return self.lastLines

    def readRooms(self):
        self.online = {}
        self.sendCommand("get-nicks")
        lines = self.sendCommand("list")
        current_room = None
        self.rooms = {}
        for line in lines:
            if line.strip() == "":
                continue
            if line.strip()[0] == '*':
                online = True
            else:
                online = False
            line = line.replace('*', ' ')
            tokens = line.strip().split()
            if line[3] != ' ':
                current_room = tokens[0]
                self.online[current_room] = online
                self.rooms[current_room] = []
            else:
                person = PersonObj()
                person.ip = tokens[0].strip()
                if len(tokens) > 1:
                    person.name = tokens[1].strip()
                else:
                    person.name = "<Unknown>"
                if len(tokens) > 2:
                    person.personal_ip = tokens[2].strip()
                else:
                    person.personal_ip = "<Unknown>"

                self.rooms[current_room].append(person)
                self.online[person.ip] = online
                self.names[person.ip] = person.name
                 
                



class HamGUI:
    def __init__(self):
        data = zlib.decompress(GLADE_DATA)
#        data = open("ham.glade").read()
        self.xml = gtk.glade.xml_new_from_buffer(data, len(data))
        self.rooms = {}
        self.interval = None
        self.timer = 0
#        sys.stdout = Output(self.output)
        self.hamCommunicator = HamParser()
        self.initWidgets()
        self.connectHandlers()


        gobject.idle_add(self.updateGUI)

        gobject.idle_add(self.xml.get_widget("hamView").expand_all)
        self.xml.get_widget("mainWindow").show_all()
        
        # try starting hamachi
        self.hamCommunicator.sendCommand("start")

    def initWidgets(self):
        self.xml.get_widget("mainWindow").set_default_size(200, 500)
        self.hamTree = gtk.TreeStore(str, str, str, bool)
        column = gtk.TreeViewColumn()

        cellStr = gtk.CellRendererText()
        cellPixbuf = gtk.CellRendererPixbuf()
        
        column.pack_start(cellPixbuf, False)
        column.pack_start(cellStr, False)
        column.add_attribute(cellPixbuf, 'stock-id', 0)
        column.set_attributes(cellStr, text=1)

        cellStr = gtk.CellRendererText()
        column.pack_start(cellStr, False)
        column.set_attributes(cellStr, text=2)
        
        self.xml.get_widget("hamView").append_column(column)



        self.xml.get_widget("hamView").set_headers_visible(False)
        self.xml.get_widget("hamView").set_model(self.hamTree)
        self.selection = self.xml.get_widget("hamView").get_selection()
        self.selection.connect('changed', self.selection_changed)

        self.xml.get_widget("newnetwork").set_property('sensitive', True)
        self.xml.get_widget("delnetwork").set_property('sensitive', False)
        self.xml.get_widget("joinnetwork").set_property('sensitive', True)
        self.xml.get_widget("leavenetwork").set_property('sensitive', False)
        self.xml.get_widget("kicknetwork").set_property('sensitive', False)

        self.outputBuffer = self.xml.get_widget("outputView").get_buffer()
        self.connectionTip = gtk.Tooltips()

    def connectHandlers(self):
        autodict = {    "network_new_clicked" : self.new_network,
                        "network_del_clicked" : self.del_network,
                        "network_join_clicked" : self.join_network,
                        "network_leave_clicked" : self.leave_network,
                        "network_kick_clicked"  : self.kick_network,
                        "cancel_clicked"        : self.hide_dialog,
                        "new_entry_changed"     : self.new_entry_changed, 
                        "dialogok_clicked"      : self.action_requested,
                        "connect_toggled"       : self.connect_toggled,
                        "refresh_clicked"       : self.refresh_clicked, 
                    "refresh_spinner_changed"   : self.refresh_changed,
                        "quit_event"            : gtk.main_quit, 
                        }

        self.xml.signal_autoconnect(autodict)
        self.interval = int(self.xml.get_widget("refresh_spinner").get_value())
        gobject.timeout_add(1000, self.GUIUpdater)

    def updateHamView(self, clear=False):
        added = {}
        if clear:
            self.hamTree.clear()
            self.rooms = {}
        for room in self.hamCommunicator.rooms.keys():
            if room in self.rooms:
                parent = self.rooms[room]
            else:
                parent = self.hamTree.append(None, [None,  room, None, self.hamCommunicator.online[room]])
                self.rooms[room] = parent
            
            try:
                iter = self.hamTree[parent].iterchildren()
                while iter:
                    row = iter.next()
                    ip = self.hamTree.get_value(row.iter, 2)
                    if ip not in self.hamCommunicator.online:
                        self.hamTree.remove(row.iter)
                    else:
                        added[ip] = True
                        row[3] = self.hamCommunicator.online[ip]
                        row[1] = self.hamCommunicator.names[ip]
            except StopIteration:
                pass

            for nick in self.hamCommunicator.rooms[room]:
                if nick.ip not in added:
                    self.hamTree.append(parent,
                            [None, nick.name,
                                nick.ip, self.hamCommunicator.online[nick.ip]])

        iter = self.hamTree.get_iter_first()
        try:
            while iter:
                if not self.hamTree.iter_is_valid(iter):
                    break
                room = self.hamTree.get_value(iter, 1)
                if room not in self.hamCommunicator.rooms:
                    self.hamTree.remove(iter)
                    del self.rooms[room]
                else:
                    iter = self.hamTree.iter_next(iter)
        except StopIteration:
            pass


        if clear:
            self.xml.get_widget("hamView").expand_all()
        
    def GUIUpdater(self):
        self.timer += 1
        if self.timer >= self.interval:
            self.updateGUI()
            self.timer = 0
        try:
            percentage = float(self.timer) / float(self.interval-1)
            if percentage > 0:
                percentage -= .001
            self.xml.get_widget("refreshprogressbar").set_fraction(percentage)
        except:
            self.xml.get_widget("refreshprogressbar").pulse()

        return True


    def updateGUI(self, interval=None):
        gtk.gdk.threads_enter()
        self.hamCommunicator.readStatus()
        self.hamCommunicator.readRooms()
        self.xml.get_widget("nicklabel").set_markup("<b><span size=\"xx-large\">%s</span></b>"%self.hamCommunicator.nickname)
        self.xml.get_widget("statuslabel").set_markup("<span>%s</span>"%(self.hamCommunicator.status))
        self.xml.get_widget("iplabel").set_markup("<b><span size=\"xx-large\">%s</span></b>"%self.hamCommunicator.identity)

        self.toggling_icon = True
        if self.hamCommunicator.status == ONLINE:
            self.xml.get_widget("connect_toggle").set_active(True)
            self.connectionTip.set_tip(self.xml.get_widget("connect_toggle"), "Disconnect")
        elif self.hamCommunicator.status == OFFLINE:
            self.xml.get_widget("connect_toggle").set_active(False)
            self.connectionTip.set_tip(self.xml.get_widget("connect_toggle"), "Connect")
        self.toggling_icon = False
        
        self.updateHamView()
        self.updateOnline()
        gtk.gdk.threads_leave()
        return self.interval == interval

    def updateOnline(self):
        for row in self.hamTree:
            if row[3]:
                row[0] = gtk.STOCK_NETWORK
            else:
                row[0] = gtk.STOCK_DISCONNECT
            for childrow in row.iterchildren():
                if childrow[3]:
                    childrow[0] = gtk.STOCK_CONNECT
                else:
                    childrow[0] = gtk.STOCK_DISCONNECT

    def output(self, text):
        end_iter = self.outputBuffer.get_end_iter()
        self.outputBuffer.insert(end_iter, text)
        end_mark = self.outputBuffer.create_mark(None, self.outputBuffer.get_end_iter(), True)
        self.xml.get_widget("outputView").scroll_to_mark(end_mark, 0)


    def new_network(self, obj):
        self.action = NEW
        self.xml.get_widget("newlabel").set_label("<b>Create New Network</b>")
        self.xml.get_widget("newname").set_text('')
        self.xml.get_widget("newpass").set_text('')
        self.xml.get_widget("newok").set_property('sensitive', False)
        self.xml.get_widget("newdialog").present()

    def del_network(self, obj):
        self.action = DELETE
        self.xml.get_widget("dellabel").set_label("<b>Delete Network</b>")
        model, row = self.selection.get_selected()
        self.xml.get_widget("delactionlabel").set_label("Delete %s Network?" %
                model.get_value(row, 1))
        self.xml.get_widget("deldialog").present()

    def join_network(self, obj):
        self.action = JOIN
        self.xml.get_widget("newlabel").set_label("<b>Join Network</b>")
        self.xml.get_widget("newname").set_text('')
        self.xml.get_widget("newpass").set_text('')
        self.xml.get_widget("newok").set_property('sensitive', False)
        self.xml.get_widget("newdialog").present()

    def leave_network(self, obj):
        self.action = LEAVE
        self.xml.get_widget("dellabel").set_label("<b>Leave Network</b>")
        model, row = self.selection.get_selected()
        self.xml.get_widget("delactionlabel").set_label("Leave %s Network?" %
                model.get_value(row, 1))
        self.xml.get_widget("deldialog").present()

    def kick_network(self, obj):
        self.action = KICK
        self.xml.get_widget("dellabel").set_label("<b>Kick from Network</b>")
        model, row = self.selection.get_selected()
        self.xml.get_widget("delactionlabel").set_label("Kick %s from Network?" %
                model.get_value(row, 1))
        self.xml.get_widget("deldialog").present()

    def hide_dialog(self, data):
        data.hide()

    def new_entry_changed(self, data):
        if self.xml.get_widget("newname").get_text().strip() != '' and \
            self.xml.get_widget("newpass").get_text().strip() != '':
            self.xml.get_widget("newok").set_property('sensitive', True)
        else:
            self.xml.get_widget("newok").set_property('sensitive', False)
         

    def selection_changed(self, selection):
        model, iter = selection.get_selected()
        if not iter:
            return
        if model.iter_parent(iter):
            self.xml.get_widget("newnetwork").set_property('sensitive', True)
            self.xml.get_widget("delnetwork").set_property('sensitive', False)
            self.xml.get_widget("joinnetwork").set_property('sensitive', True)
            self.xml.get_widget("leavenetwork").set_property('sensitive', False)
            self.xml.get_widget("kicknetwork").set_property('sensitive', True)
            # it's a user.
        else:
            # it's a room
            self.xml.get_widget("newnetwork").set_property('sensitive', True)
            self.xml.get_widget("delnetwork").set_property('sensitive', True)
            self.xml.get_widget("joinnetwork").set_property('sensitive', True)
            self.xml.get_widget("leavenetwork").set_property('sensitive', True)
            self.xml.get_widget("kicknetwork").set_property('sensitive', False)

    def connect_toggled(self, obj):
        if self.toggling_icon:
            return
        if self.hamCommunicator.status == ONLINE:
            self.hamCommunicator.sendCommand("logout")
        elif self.hamCommunicator.status == OFFLINE:
            self.hamCommunicator.sendCommand("login")
        return True


    def refresh_clicked(self, obj):
        gobject.idle_add(self.updateGUI)

    def refresh_changed(self, obj): 
        interval = int(obj.get_value())
        self.interval = interval

    def action_requested(self, obj):
        if not self.xml.get_widget("newok").get_property('sensitive'):
            return
        self.xml.get_widget("newdialog").hide()
        self.xml.get_widget("deldialog").hide()

        if self.action == NEW:
            room = self.xml.get_widget("newname").get_text().strip()
            passw = self.xml.get_widget("newpass").get_text().strip()
            self.hamCommunicator.sendCommand("new", room, passw)

        if self.action == DELETE:
            model, iter = self.selection.get_selected()
            room = model.get_value(iter, 1).strip('[]')
            self.hamCommunicator.sendCommand("delete", room)

        if self.action == LEAVE:
            model, iter = self.selection.get_selected()
            room = model.get_value(iter, 1).strip('[]')
            self.hamCommunicator.sendCommand("go-offline", room)
            self.hamCommunicator.sendCommand("leave", room)

        if self.action == JOIN:
            room = self.xml.get_widget("newname").get_text().strip()
            passw = self.xml.get_widget("newpass").get_text().strip()
            self.hamCommunicator.sendCommand("join", room, passw)
            self.hamCommunicator.sendCommand("go-online", room)

        if self.action == KICK:
            pass

        
        print self.hamCommunicator.lastOutput

def main():
    app = HamGUI()
    gtk.main()

GLADE_DATA='x\x9c\xed]Ks\xdb6\x10\xbe\xf7W\xb0<t\xda\x83b[n\xd26\xb1\x95\xfa\xa1$nl\xcbc)u}\xe2@$,1\x82\x08\x96\x04-\xa9\xd3\x1f\xdf%H\xcb\x94\x08\x92\xe0K\xa6\x1a]<\xe2\x03\x8b\xdd\xc5\xee\x87]\x10\x0b\x1f\xbd\x9fO\x89\xf2\x88\x1d\xd7\xa4\xd6\xb1z\xf0j_U\xb0\xa5S\xc3\xb4F\xc7\xea\x97\xc1\x87\xd6\xaf\xaa\xe22d\x19\x88P\x0b\x1f\xab\x16U\xdfw\xbe;\xfa\xfe\xbcw6\xb8\xbf\xe9*#\x82\x0c\xdc2-\x86\x9d\x07\xa4c\xa5\x7f\xdf\x1ft\xaf\x145\xb8\xdf~\xb5\xff\xca`\x86\xea\xb7h\xb5>b\x0b;\x88aC\x99\x99l\x1c4=T\x0e\xe1\x9d\xb6B-\xe5\x0e\x1e\x9cc]i\xef+\x07\xbf\xbd=h\xbf=\xfc\x05~\xef\xbfQ\x86\x0b\xc5\xb2\xfe\xa1c\xe4\xfc~v\x89\xee[- \xb7\xd6o\xe7;E9\x9a\x99\xc6\x083E\'\xc8u\x8f\xd5\x8flrgZ\x06\x9d\xa9\x8ai\x1c\xabSdZ\xe1\xb5\xff2\xbcn;\xd4\xc6\x0e\x03\xe2h\n\x921\x93\x11\xac*\xccA\x96K\x10CC\x027\x17\xd8U;\x9f\xd0\x14\xe9c\xf3h\xef\xa9\x85\x98\x80\x81\x1f\x90G\x986\xc6\xe6h\xcc\xd4N\xfb\xf5~\xac\x89k\x8e,D\x96\r\x08fX\xc3\x8f\xd8b\xaa2\x06%\x13\xec\x1c\xab\x7f{&\x0bo\xee\x85\xcd\xa0w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